package cn.tedu.boot01.controller;

import cn.tedu.boot01.entity.User;
import cn.tedu.boot01.util.DBUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@Controller
public class UserController {
    @RequestMapping("/regUser")
    @ResponseBody
    public String reg(User user){
        System.out.println("user = " + user);
        try(Connection conn = DBUtil.getConnection()) {

            String sql = "insert into user values (null ,?,?,?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1,user.getUsername());
            ps.setString(2,user.getPassword());
            ps.setString(3,user.getNickname());
            ps.executeUpdate();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return "注册成功";
    }
}
